package top.zk123.chain.mapper;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import top.zk123.chain.bean.CertificateTmp;

import java.util.List;

public interface CertificateTmpMapper extends JpaRepository<CertificateTmp, String> {
    /**
     * 依照InstitutionId 进行查询, 并且进行分页操作
     *
     * @param institutionId 机构标识
     * @param pageable      是否进行分页
     * @return Page 对象列表的子列表
     */
    @Query(value = "select * from certificate_tmp where institution_id = :institutionId", nativeQuery = true)
    Page<CertificateTmp> findByInstitutionId(String institutionId, Pageable pageable);

    /**
     * 依照 institutionId 进行查询.
     *
     * @param institutionId 机构标识
     * @return 集合 {@link CertificateTmp}
     */
    @Query(value = "select * from certificate_tmp where institution_id = :institutionId", nativeQuery = true)
    List<CertificateTmp> findByInstitutionId(String institutionId);

    /**
     * 通过 uid 查询 certificateTmp 库
     * @param uid 证书标识
     * @return {@link CertificateTmp}
     */
    @Query(value = "select * from certificate_tmp where uid = :uid", nativeQuery = true)
    CertificateTmp findByUid(long uid);
}
